<template>
  <div class="app-container">
    <eHeader :query="query" :dict="dict" :sup_this="sup_this"/>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <el-table-column prop="id" label="id"/>
      <el-table-column prop="mapName" label="地图名称"/>
      <el-table-column prop="mapUrl" label="地图预览">
        <!--<template slot-scope="scope">-->
          <!--<img :src="scope.row.mapUrl" class="image_column"/>-->
        <!--</template>-->
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="hover">
            <img :src="scope.row.mapUrl" style="max-height: 150px;max-width: 300px"/>
            <img slot="reference" :src="scope.row.mapUrl" :alt="scope.row.mapUrl" style="max-height: 50px;max-width: 130px">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="mapRealHeight" label="场地长">
        <template slot-scope="scope">
          {{scope.row.mapRealHeight}}米
        </template>
      </el-table-column>
      <el-table-column prop="mapRealWidth" label="场地宽">
        <template slot-scope="scope">
          {{scope.row.mapRealWidth}}米
        </template>
      </el-table-column>

      <el-table-column label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <edit :dict="dict" :data="scope.row" :sup_this="sup_this"/>
          <el-popover
            :ref="scope.row.id"
            placement="top"
            width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定
              </el-button>
            </div>
            <el-button slot="reference" type="danger" size="mini">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
  import initData from '@/mixins/initData'
  import {del, getDict} from '@/api/deviceMap'
  import {parseTime} from '@/utils/index'
  import eHeader from './module/header'
  import edit from './module/edit'
  export default {
    components: {eHeader, edit},
    mixins: [initData],
    data() {
      return {
        delLoading: false, sup_this: this,
        dict: {}
      }
    },
    created() {
      this.$nextTick(() => {
        this.init()
        this.getDict()
      })
    },
    methods: {
      parseTime,
      getDict(){
        getDict().then(res => {
          this.dict = res
        }).catch(err => {
          console.log(err.response.data.message)
        })
      },
      beforeInit() {
        this.url = 'api/deviceMap'
        const sort = 'id,desc'
        this.params = {page: this.page, size: this.size, sort: sort}
        return true
      },
      subDelete(id) {
        this.delLoading = true
        del(id).then(res => {
          this.delLoading = false
          this.$refs[id].doClose()
          this.init()
          this.$notify({
            title: '删除成功',
            type: 'success',
            duration: 2500
          })
        }).catch(err => {
          this.delLoading = false
          this.$refs[id].doClose()
          console.log(err.response.data.message)
        })
      }
    }
  }
</script>

<style scoped>
  .image_column {
    width: 100px;
    height: 100px;
  }
</style>
